﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
    public static class StringExtention
    {
        #region JoinToString 转换成分隔符隔开字符串
        /// <summary>
        /// 转换成分隔符隔开字符串
        /// </summary>
        public static string JoinToString(this IList<string> list, string separator)
        {
            return string.Join(separator, list);
        }

        /// <summary>
        /// 转换成分隔符隔开字符串
        /// </summary>
        public static string JoinToString(this IList<string> list, char separator = ',')
        {
            return string.Join(separator, list);
        }
        #endregion

        #region JoinToString<T> 转换成分隔符隔开字符串
        /// <summary>
        /// 转换成分隔符隔开字符串
        /// </summary>
        public static string JoinToString<T>(this IList<T> list, Converter<T, string> converter, string separator)
        {
            var strList = new List<string>();
            foreach (var item in list)
            {
                strList.Add(converter(item));
            }
            return string.Join(separator, strList);
        }

        /// <summary>
        /// 转换成分隔符隔开字符串
        /// </summary>
        public static string JoinToString<T>(this IList<T> list, Converter<T, string> converter, char separator = ',')
        {
            var strList = new List<string>();
            foreach (var item in list)
            {
                strList.Add(converter(item));
            }
            return string.Join(separator, strList);
        }
        #endregion

    }
}
